﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RWLib
{
    class ActionExecutabilityQuery :Query
    {

        private string actionName;

        public ActionExecutabilityQuery(Tree _tree, string _actionName)
        {
            this.actionName=_actionName;
            this.tree = _tree;
        }

        override public bool Run()
        {
            List<Node> children = tree.Root.Nodes;
            while (children.Count>0)
            {                
                if (children.Any(c => c.actions.Any(a =>a.Name.Equals(actionName))))
                {
                    return true;
                }
                children = children.Select(c => c.Nodes).SelectMany(c => c).ToList();
            }
            return false;
        }

    }
}